﻿namespace Community.CsharpSqlite.Entity
{
    /*
     ** Each SQL function is defined by an instance of the following
     ** structure.  A pointer to this structure is stored in the sqlite.aFunc
     ** hash table.  When multiple functions have the same name, the hash table
     ** points to a linked list of these structures.
     */

    public class FuncDef
    {
        public byte flags; /* Some combination of SQLITE_FUNC_* */
        public byte iPrefEnc; /* Preferred text encoding (Const.SQLITE_UTF8, 16LE, 16BE) */
        public short nArg; /* Number of arguments.  -1 means unlimited */
        public FuncDef pHash; /* Next with a different name but the same hash */
        public FuncDef pNext; /* Next function with same name */
        public object pUserData; /* User data parameter */
        public dxFinal xFinalize; //)(sqlite3_context*);                /* Aggregate finalizer */
        public dxFunc xFunc; //)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
        public dxStep xStep; //)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
        public string zName; /* SQL name of the function. */


        public FuncDef()
        {
        }

        public FuncDef(short nArg, byte iPrefEnc, byte iflags, object pUserData, FuncDef pNext, dxFunc xFunc,
                       dxStep xStep, dxFinal xFinalize, string zName, FuncDef pHash)
        {
            this.nArg = nArg;
            this.iPrefEnc = iPrefEnc;
            flags = iflags;
            this.pUserData = pUserData;
            this.pNext = pNext;
            this.xFunc = xFunc;
            this.xStep = xStep;
            this.xFinalize = xFinalize;
            this.zName = zName;
            this.pHash = pHash;
        }

        public FuncDef(string zName, byte iPrefEnc, short nArg, int iArg, byte iflags, dxFunc xFunc)
        {
            this.nArg = nArg;
            this.iPrefEnc = iPrefEnc;
            flags = iflags;
            pUserData = iArg;
            pNext = null;
            this.xFunc = xFunc;
            xStep = null;
            xFinalize = null;
            this.zName = zName;
        }

        public FuncDef(string zName, byte iPrefEnc, short nArg, int iArg, byte iflags, dxStep xStep, dxFinal xFinal)
        {
            this.nArg = nArg;
            this.iPrefEnc = iPrefEnc;
            flags = iflags;
            pUserData = iArg;
            pNext = null;
            xFunc = null;
            this.xStep = xStep;
            xFinalize = xFinal;
            this.zName = zName;
        }

        public FuncDef(string zName, byte iPrefEnc, short nArg, object arg, dxFunc xFunc, byte flags)
        {
            this.nArg = nArg;
            this.iPrefEnc = iPrefEnc;
            this.flags = flags;
            pUserData = arg;
            pNext = null;
            this.xFunc = xFunc;
            xStep = null;
            xFinalize = null;
            this.zName = zName;
        }
    };
}